//
//  WDAboutViewController.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/17.
//

#import "WDAboutViewController.h"
#import "WDAboutViewModel.h"

@interface WDAboutViewController ()
@property (nonatomic, strong) WDAboutViewModel *viewModel;

@property (nonatomic, strong) UIImageView *logoImgView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation WDAboutViewController

- (void)dealloc {
    debugMethod();
}

- (void)initWithVar {
    [super initWithVar];
    
}

- (void)initWithViewModel {
    _viewModel = [WDAboutViewModel new];
    
    [_viewModel setupData];
}

- (void)initWithNavBar {
    [super initWithNavBar];
    
    [self initWithBackButton];
    
    self.navigationItem.title = self.viewModel.title;
}

- (void)initWithSubView {
    [super initWithSubView];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initWithLogoImgView];
    
    [self initWithTitleLabel];
    
    [self initWithRootContent:NO];
    self.rootContent.top = self.titleLabel.bottom + 16;
    self.rootContent.height = kScreenH - NAVBAR_HEIGHT_STATUS - self.titleLabel.bottom - 16 - IPHONEX_BOTTOM_SPACE;
//    self.rootContent.backgroundColor = [UIColor orangeColor];
    
    [self initWithContentLabel];
}

- (void)initWithLogoImgView {
    if (!_logoImgView) {
        UIImage *image = [UIImage imageNamed:@"ic-mine-logo"];
        CGRect frame = CGRectMake((kScreenW - image.size.width) * 0.5, 20, image.size.width, image.size.height);
        _logoImgView = [UIImageView createWithImageView:self.view frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            
        }];
    }
}

- (void)initWithTitleLabel {
    CGRect frame = CGRectMake(20, _logoImgView.bottom + 15, kScreenW - 40, 22);
    UIFont *font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    _titleLabel = [UILabel createWithLabel:self.view frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
        label.textColor = [UIColor colorWithHexString:@"#000000"];
        label.text = @"苇渡集团";
        label.textAlignment = NSTextAlignmentCenter;
    }];
}

- (void)initWithContentLabel {
    if (!_contentLabel) {
        UIFont *font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
        float width = kScreenW - 40;
        float height = [self.viewModel.content heightForFont:font width:width];
        CGRect frame = CGRectMake(20, 0, width, height);
        _contentLabel = [UILabel createWithLabel:self.rootContent frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor blackColor];
            label.text = self.viewModel.content;
            label.numberOfLines = 0;
        }];
    }
    if (_contentLabel.height > self.rootContent.height) {
        self.rootContent.contentSize = CGSizeMake(kScreenW, _contentLabel.height + 20);
    } else {
        self.rootContent.contentSize = CGSizeMake(kScreenW, self.rootContent.height);
    }
}

@end
